package psd.model.Prolog.Converters;

import java.util.Iterator;

import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.InfixExpression;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologInfixExpressionConverter extends PrologConverter implements
		IConverter<InfixExpression> {

	public PrologInfixExpressionConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(InfixExpression node) {
		StringBuffer operands = new StringBuffer();
		operands.append("[");
		operands.append(idResolver.getID(node.getLeftOperand()));
		operands.append(", ");
		operands.append(idResolver.getID(node.getRightOperand()));
		Expression extop;
		for (Iterator it = node.extendedOperands().iterator(); it.hasNext(); operands
				.append(idResolver.getID(extop))) {
			extop = (Expression) it.next();
			operands.append(", ");
		}

		operands.append("]");
		String args[] = {
				operands.toString(),
				(new StringBuilder("'")).append(node.getOperator().toString())
						.append("'").toString(), "0" };
		createBodyFact(node, "operationT", args);
		return true;
	}

}
